package com.wzdigit.wms.wms.controller.inv.count;

import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.wms.client.request.inv.count.dto.ResultApprDto;
import com.wzdigit.wms.wms.client.response.inv.count.*;
import com.wzdigit.wms.wms.client.response.inv.count.dto.InvSeqDto;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.inv.count.InvCountReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;

/**
 * 盘点报表BS
 * Created by zyf on 2021/10/16 9:33
 */
@RestController
@Api(tags = "盘点报表")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class InvCounrReportController {
    public static final String REQUEST_MODEL = "/countReport";

    @Autowired
    private InvCountReportService reportService;

    @ApiOperation(value = "盘点差异报表（分页）", notes = "盘点差异报表（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/searchDif", method = RequestMethod.GET)
    public PagerInfo<List<CountDifDtlResponse>> searchCountDif(
            BigDecimal headerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchCountDif(headerId,pager);
    }

    @ApiOperation(value = "盘点差异SN明细（分页）", notes = "盘点差异SN明细（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/dif/goods", method = RequestMethod.GET)
    public PagerInfo<List<CountDifGoodsRespone>> searchCountDifGoods(
            BigDecimal difId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchCountDifGoods(difId,pager);
    }

    @ApiOperation(value = "盘点范围报表（分页）", notes = "盘点范围报表（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/searchScope", method = RequestMethod.GET)
    public PagerInfo<List<CoutnScopeRespnse>> searchCountScope(
            BigDecimal headerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchCountScope(headerId,pager);
    }

    @ApiOperation(value = "盘点任务明细报表（分页）", notes = "盘点任务明细报表（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/searchDtl", method = RequestMethod.GET)
    public PagerInfo<List<CountDtlResponse>> searchCountDtl(
            BigDecimal headerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchCountDtl(headerId,pager);
    }

    @ApiOperation(value = "复盘任务明细报表（分页）", notes = "复盘任务明细报表（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/searchReDtl", method = RequestMethod.GET)
    public PagerInfo<List<ReCountDtlResponse>> searchReCountDtl(
            BigDecimal headerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchReCountDtl(headerId,pager);
    }

    @ApiOperation(value = "初/复任务SN明细（分页）", notes = "初/复任务SN明细（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/dtl/goods", method = RequestMethod.GET)
    public PagerInfo<List<CountDtlGoodsRespone>> searchCountDtlGoods(
            BigDecimal dtlId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchCountDtlGoods(dtlId,pager);
    }

    @ApiOperation(value = "盘点结果汇总（分页）", notes = "盘点结果汇总（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/allResult", method = RequestMethod.GET)
    public PagerInfo<List<CountAllResultResponse>> searchAllResult(
            BigDecimal headerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchAllResult(headerId,pager);
    }

    @ApiOperation(value = "盘点信息汇总表导出", notes = "盘点信息汇总表导出")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/exportAll", method = RequestMethod.GET)
    public void exportAll(
            BigDecimal headerId,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            reportService.exportAll(headerId,servletRequest,servletResponse);
            //lotInvReportService.exportSaleInvReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "盘点结果-盘点结果明细（分页）", notes = "盘点结果-盘点结果明细（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/searchAprResul/dtl", method = RequestMethod.GET)
    public PagerInfo<List<CountAprResultResponse>> searchAprResultDtl(
            BigDecimal headerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchAprResultDtl(headerId,pager);
    }

    @ApiOperation(value = "盘点结果-盘点差异（分页）", notes = "盘点结果-盘点差异（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/searchAprResul/dif", method = RequestMethod.GET)
    public PagerInfo<List<CountAprResultResponse>> searchAprDif(
            BigDecimal headerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reportService.searchAprDif(headerId,pager);
    }

    @ApiOperation(value = "盘点结果-盘点履历（分页）", notes = "盘点结果-盘点履历（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/searchAprResul/seq", method = RequestMethod.GET)
    public PagerInfo<List<InvSeqDto>> searchInvSeq(
            BigDecimal dtlId,Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return reportService.searchInvSeq(dtlId,pager);
            //lotInvReportService.exportSaleInvReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "盘点结果审核", notes = "盘点结果审核")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/searchAprResul/commit", method = RequestMethod.POST)
    public Result<String> resultAppr(
            @RequestBody ResultApprDto dto,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return reportService.resultApprNew(dto,servletRequest);
            //lotInvReportService.exportSaleInvReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "盘点差异调账明细", notes = "盘点差异调账明细")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/difAdj/dtl", method = RequestMethod.GET)
    public List<CountAprResultResponse> searchDifDtl(
            BigDecimal headerId,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return reportService.searchDifDtl(headerId);
            //lotInvReportService.exportSaleInvReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "盘点差异调账", notes = "盘点差异调账")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/difAdj/commit", method = RequestMethod.POST)
    public Result<String> dfiAdj(
            @RequestBody List<BigDecimal> hederIds,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return reportService.dfiAdjLast(hederIds,servletRequest);
            //lotInvReportService.exportSaleInvReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }


}
